<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('新增联系记录')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: summernote-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-record-add">
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">联系人ID：</label>
                    <div class="col-sm-8">
                        <input name="contactId" class="form-control" type="text" required>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">联系类型：</label>
                    <div class="col-sm-8">
                        <select class="form-control" id="contactType" name="contactType">
                            <option value="">请选择联系类型</option>
                            <optgroup label="线下沟通">
                                <option value="见面">见面</option>
                                <option value="电话">电话</option>
                                <option value="会议">会议</option>
                            </optgroup>
                            <optgroup label="线上沟通">
                                <option value="微信聊天">微信聊天</option>
                                <option value="QQ聊天">QQ聊天</option>
                                <option value="邮件">邮件</option>
                                <option value="社交媒体">社交媒体</option>
                            </optgroup>
                            <optgroup label="视频会议">
                                <option value="腾讯会议">腾讯会议</option>
                                <option value="Zoom">Zoom</option>
                                <option value="Teams">Teams</option>
                            </optgroup>
                            <optgroup label="其他方式">
                                <option value="短信">短信</option>
                                <option value="邮件">邮件</option>
                                <option value="社交媒体">社交媒体</option>
                            </optgroup>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">联系内容：</label>
                    <div class="col-sm-8">
                        <input type="hidden" class="form-control" name="contactContent">
                        <div class="summernote" id="contactContent"></div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label is-required">联系时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="contactTime" class="form-control" placeholder="yyyy-MM-dd" type="text" required>
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="col-xs-12">
                <div class="form-group">
                    <label class="col-sm-3 control-label">下次联系时间：</label>
                    <div class="col-sm-8">
                        <div class="input-group date">
                            <input name="nextContactTime" class="form-control" placeholder="yyyy-MM-dd" type="text">
                            <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: summernote-js" />
    <script th:inline="javascript">
        var prefix = ctx + "contact/record"
        $("#form-record-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.save(prefix + "/add", $('#form-record-add').serialize());
            }
        }

        $("input[name='contactTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("input[name='nextContactTime']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $(function() {
            $('.summernote').summernote({
                lang: 'zh-CN',
                dialogsInBody: true,
                callbacks: {
                    onChange: function(contents, $edittable) {
                        $("input[name='" + this.id + "']").val(contents);
                    },
                    onImageUpload: function(files) {
                        var obj = this;
                    	var data = new FormData();
                    	data.append("file", files[0]);
                    	$.ajax({
                            type: "post",
                            url: ctx + "common/upload",
                    		data: data,
                    		cache: false,
                    		contentType: false,
                    		processData: false,
                    		dataType: 'json',
                    		success: function(result) {
                    		    if (result.code == web_status.SUCCESS) {
                    		        $('#' + obj.id).summernote('insertImage', result.url);
                    		    } else {
                    		        $.modal.alertError(result.msg);
                    		    }
                    		},
                    		error: function(error) {
                    		    $.modal.alertWarning("图片上传失败。");
                    		}
                    	});
                    }
                }
            });
        });
    </script>
</body>
</html>